/**
 * Created by Administrator on 2016/3/11 0011.
 */


function areaChange(obj, selectname, minselectname) {
    var index = obj.selectedIndex;
    var thisVal = obj.options[index].value;
    // console.log(thisVal);
    $.ajax({
        url: 'getArea.shtml',
        data: {
            "area": thisVal,
            "type": selectname
        },
        type: "post",
        dataType: "json",
        success: function (data) {
            var select = document.getElementById(selectname);
            select.length = 0;
            var minselect = document.getElementById(minselectname);
            minselect.length = 0;
            minselect.options[0] = new Option("请选择", '');
            select.options[0] = new Option("请选择", '');
            $.each(data, function (item, element) {
                select.options[select.length] = new Option(element, element);
            });
        }
    })

}

function checkifnull(str) {
    if (str == null) {
        return "暂无数据";
    } else {
        return str;
    }
}

$(function () {

    $("#counttable").hide();
    $('#searchEnergy').click(function(){
        searchEnergy();
    });


        function searchEnergy() {
        $.ajax({
            url: 'excuteCountManyAjax.shtml?' + $.param($("#countForm").serializeObject()),
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data != null && data.length > 0) {
                    $("#nodatas").hide();
                    $("#counttable").show();
                    $("#countcompanycode td:gt(0)").remove();
                    $("#countcustomername td:gt(0)").remove();
                    $("#countemployeenum td:gt(0)").remove();
                    $("#countsquare td:gt(0)").remove();
                    $("#countstreet td:gt(0)").remove();
                    $("#countrealpower td:gt(0)").remove();
                    $("#countlightpower td:gt(0)").remove();
                    $("#countairpower td:gt(0)").remove();
                    $("#countunitsquare td:gt(0)").remove();
                    $("#countunitperson td:gt(0)").remove();
                    _.pluck(data, 'companycode');
                    $.each(data, function (item) {
                        $("#countcompanycode").append("<td>" + checkifnull(_.pluck(data, 'companycode')[item]) + "</td>");
                        $("#countcustomername").append("<td>" + checkifnull(_.pluck(data, 'customername')[item]) + "</td>");
                        $("#countemployeenum").append("<td>" + checkifnull(_.pluck(data, 'employeenum')[item]) + "</td>");
                        $("#countsquare").append("<td>" + checkifnull(_.pluck(data, 'square')[item]) + "</td>");
                        $("#countstreet").append("<td>" + checkifnull(_.pluck(data, 'street')[item]) + "</td>");
                        $("#countrealpower").append("<td>" + checkifnull(_.pluck(data, 'realpower')[item]) + "</td>");
                        $("#countlightpower").append("<td>" + checkifnull(_.pluck(data, 'lightpower')[item]) + "</td>");
                        $("#countairpower").append("<td>" + checkifnull(_.pluck(data, 'airpower')[item]) + "</td>");
                        $("#countunitsquare").append("<td>" + checkifnull(_.pluck(data, 'unitsquare')[item]) + "</td>");
                        $("#countunitperson").append("<td>" + checkifnull(_.pluck(data, 'unitperson')[item]) + "</td>");
                    });
                } else {
                    $("#nodatas").show();
                    $("#counttable").hide();
                }
            }
        })
    }
});